package com.example.demo;

import com.fasterxml.jackson.databind.ObjectWriter;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.function.Function;

import static org.springframework.http.ResponseEntity.ok;

/**
 * @author fanhb on 2020/8/5
 * @desc xxxx
 */
public class FluxDemo2 {

    public static void main(String[] args) {
        Function<Integer, Integer> times2 = i -> i*2;
        Function<Integer, Integer> squared = i -> i*i;

        System.out.println(times2.apply(4));

        System.out.println(squared.apply(4));

        //32                先4×4然后16×2,先执行apply(4)，在times2的apply(16),先执行参数，再执行调用者。
        Function<Integer, Integer> compose = times2.compose(squared);


        System.out.println(compose.apply(4));

        //64               先4×2,然后8×8,先执行times2的函数，在执行squared的函数。
        System.out.println(times2.andThen(squared).apply(4));

        //16
        Function<Object, Object> identity = Function.identity();
        System.out.println(identity.compose(squared).apply(4));
        System.out.println(identity.apply("hello"));
    }

}
